﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

using RexToy.UI.WinForm.ViewModel;

namespace RexToy.UI.WinForm.Controls
{
    public class MenuItem : ToolStripMenuItem, IBindCommand
    {
        public MenuItem()
        {
            this.Click += new EventHandler(MenuItem_Click);
        }

        void MenuItem_Click(object sender, EventArgs e)
        {
            if (_cmd != null)
                _cmd.Execute();
        }

        private IUICommand _cmd;
        public IUICommand Command
        {
            get { return _cmd; }
            set
            {
                CommandBindRegistry.Instance().PutItem(this);
                _cmd = value;
            }
        }

        public void QueryCanExecute()
        {
            if (_cmd != null)
                this.Enabled = _cmd.CanExecute();
        }
    }
}
